const Mock = require('mockjs')

const data = Mock.mock({
  'items|12': [{
    userId: '@id',
    account: '@integer(10, 1000000)',
    realName: '@cname',
    position: '@integer(10, 50)',
    gender: 1,
    'sex|1': ['M', 'F'],
    positionName: '@cposition',
    orgName: '河钢数字',
    avatar: '10000'
  }],
  'roles|15': [{
    roleId: '@id',
    roleCode: '@integer(10, 50)',
    roleName: '@roleName',
    roleType: '1',
    followAppName: '@appName',
    isSelected: '1|0'
  }],
  groItem: [
    {
      checked: true,
      children: null,
      iconSkin: null,
      id: '1339554696976781407',
      name: '河钢集团',
      nodeId: '1339554696976781407',
      nodeParentId: '-1',
      open: true
    },
    {
      checked: true,
      children: null,
      iconSkin: null,
      id: '13395546969767814072',
      name: '河钢集团2',
      nodeId: '13395546969767814072',
      nodeParentId: '-1',
      open: true
    }
  ]
})
module.exports = [
  {
    url: '/businessUser/orgTree', // 业务用户授权-左侧组织树查询
    type: 'get',
    response: (config) => {
      // const items = data.groItem
      // const { pageNo = 1, pageSize = 10 } = config.query
      // const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      // return {
      //   code: '00000',
      //   data: {
      //     totalRows: items.length,
      //     rows: pageList
      //   }
      // }
      const items = data.groItem
      return {
        code: '00000',
        success: 'true',
        message: 'success',
        data: items
      }
    }
  },
  // 业务用户授权-右侧用户列表分页查询（带查询条件）
  {
    url: '/businessUser/userPage',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  // get user info
  {
    url: '/businessUser/userDetail',
    type: 'get',
    response: (config) => {
      const { items } = data
      return {
        code: '00000',
        success: 'true',
        message: 'success',
        data: items[0]
      }
    }
  },
  // 业务用户授权-基于角色授权-查询用户角色列表
  {
    url: '/businessUser/grantUserRoleList',
    type: 'get',
    response: (config) => {
      const items = data.roles
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  // 添加角色-查询当前登录人所在管理员组角色列表
  // {
  //   url: '/businessUser/userRoleList',
  //   type: 'get',
  //   response: config => {
  //     const items = data.roles
  //     const { pageNo = 1, pageSize = 10 } = config.query
  //     const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
  //     return {
  //       code: '00000',
  //       data: {
  //         totalRows: items.length,
  //         rows: pageList
  //       }
  //     }
  //   }
  // },

  // 业务用户授权-基于角色授权-添加角色-保存
  {
    url: '/businessUser/batchAddRole',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        success: true,
        message: 'success',
        data: 'success'
      }
    }
  },
  // 业务用户授权-基于角色授权-删除（支持批量删除)
  {
    url: '/businessUser/batchDeleteRole',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        success: true,
        message: 'success',
        data: 'success'
      }
    }
  }
]
